package com.kumarn.android.catdroid.full;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;

public class SettingActivity extends Activity {

	private SharedPreferences pref;

	private ToggleButton ACTION_BATTERY_OKAY_ToggleButton;
	private ToggleButton ACTION_BATTERY_LOW_ToggleButton;
	private ToggleButton ACTION_POWER_CONNECTED_ToggleButton;
	private ToggleButton ACTION_POWER_DISCONNECTED_ToggleButton;
	private ToggleButton ACTION_SCREEN_ON_ToggleButton;
	private ToggleButton ACTION_SCREEN_OFF_ToggleButton;
	private ToggleButton ACTION_DATE_CHANGED_ToggleButton;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		pref = getSharedPreferences("CatDroidPref",MODE_WORLD_READABLE|MODE_WORLD_WRITEABLE);

		//ケーブル接続
		ACTION_BATTERY_OKAY_ToggleButton = (ToggleButton) findViewById(R.id.ACTION_BATTERY_OKAY);
		ACTION_BATTERY_OKAY_ToggleButton.setOnCheckedChangeListener(ACTION_BATTERY_OKAY_ToggleListener);
		ACTION_BATTERY_OKAY_ToggleButton.setChecked(pref.getBoolean("ACTION_BATTERY_OKAY", false));

		//ケーブル接続
		ACTION_BATTERY_LOW_ToggleButton = (ToggleButton) findViewById(R.id.ACTION_BATTERY_LOW);
		ACTION_BATTERY_LOW_ToggleButton.setOnCheckedChangeListener(ACTION_BATTERY_LOW_ToggleListener);
		ACTION_BATTERY_LOW_ToggleButton.setChecked(pref.getBoolean("ACTION_BATTERY_LOW", false));

		//ケーブル接続
		ACTION_POWER_CONNECTED_ToggleButton = (ToggleButton) findViewById(R.id.ACTION_POWER_CONNECTED);
		ACTION_POWER_CONNECTED_ToggleButton.setOnCheckedChangeListener(ACTION_POWER_CONNECTED_ToggleListener);
		ACTION_POWER_CONNECTED_ToggleButton.setChecked(pref.getBoolean("ACTION_POWER_CONNECTED", false));

		//ケーブル取り外し
		ACTION_POWER_DISCONNECTED_ToggleButton = (ToggleButton) findViewById(R.id.ACTION_POWER_DISCONNECTED);
		ACTION_POWER_DISCONNECTED_ToggleButton.setOnCheckedChangeListener(ACTION_POWER_DISCONNECTED_ToggleListener);
		ACTION_POWER_DISCONNECTED_ToggleButton.setChecked(pref.getBoolean("ACTION_POWER_DISCONNECTED", false));

		//スクリーンON
		ACTION_SCREEN_ON_ToggleButton = (ToggleButton) findViewById(R.id.ACTION_SCREEN_ON);
		ACTION_SCREEN_ON_ToggleButton.setOnCheckedChangeListener(ACTION_SCREEN_ON_ToggleListener);
		ACTION_SCREEN_ON_ToggleButton.setChecked(pref.getBoolean("ACTION_SCREEN_ON", false));

		//スクリーンOFF
		ACTION_SCREEN_OFF_ToggleButton = (ToggleButton) findViewById(R.id.ACTION_SCREEN_OFF);
		ACTION_SCREEN_OFF_ToggleButton.setOnCheckedChangeListener(ACTION_SCREEN_OFF_ToggleListener);
		ACTION_SCREEN_OFF_ToggleButton.setChecked(pref.getBoolean("ACTION_SCREEN_OFF", false));

		//日付変更
		ACTION_DATE_CHANGED_ToggleButton = (ToggleButton) findViewById(R.id.ACTION_DATE_CHANGED);
		ACTION_DATE_CHANGED_ToggleButton.setOnCheckedChangeListener(ACTION_DATE_CHANGED_ToggleListener);
		ACTION_DATE_CHANGED_ToggleButton.setChecked(pref.getBoolean("ACTION_DATE_CHANGED", false));

		Intent serviceIntent = new Intent(this,CatDroidService.class);
		this.startService(serviceIntent);
	}

	OnCheckedChangeListener ACTION_BATTERY_OKAY_ToggleListener = new OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton compoundbutton, boolean flag) {
			Editor e = pref.edit();
			e.putBoolean("ACTION_BATTERY_OKAY", flag);
			e.commit();
		}
	};

	OnCheckedChangeListener ACTION_BATTERY_LOW_ToggleListener = new OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton compoundbutton, boolean flag) {
			Editor e = pref.edit();
			e.putBoolean("ACTION_BATTERY_LOW", flag);
			e.commit();
		}
	};

	OnCheckedChangeListener ACTION_POWER_CONNECTED_ToggleListener = new OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton compoundbutton, boolean flag) {
			Editor e = pref.edit();
			e.putBoolean("ACTION_POWER_CONNECTED", flag);
			e.commit();
		}
	};

	OnCheckedChangeListener ACTION_POWER_DISCONNECTED_ToggleListener = new OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton compoundbutton, boolean flag) {
			Editor e = pref.edit();
			e.putBoolean("ACTION_POWER_DISCONNECTED", flag);
			e.commit();
		}
	};

	OnCheckedChangeListener ACTION_SCREEN_ON_ToggleListener = new OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton compoundbutton, boolean flag) {
			Editor e = pref.edit();
			e.putBoolean("ACTION_SCREEN_ON", flag);
			e.commit();
		}
	};

	OnCheckedChangeListener ACTION_SCREEN_OFF_ToggleListener = new OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton compoundbutton, boolean flag) {
			Editor e = pref.edit();
			e.putBoolean("ACTION_SCREEN_OFF", flag);
			e.commit();
		}
	};

	OnCheckedChangeListener ACTION_DATE_CHANGED_ToggleListener = new OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton compoundbutton, boolean flag) {
			Editor e = pref.edit();
			e.putBoolean("ACTION_DATE_CHANGED", flag);
			e.commit();
		}
	};

	/**
	private Menu menu;
	private static final int MENU1 = 1;

	@Override
	public boolean onCreateOptionsMenu(Menu menu1) {
		menu = menu1;
		menu.add(Menu.NONE, MENU1, Menu.NONE, "Infomation");
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		return super.onPrepareOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		boolean ret = true;
		switch (item.getItemId()) {
		default:
			ret = super.onOptionsItemSelected(item);
			break;
		case MENU1:
			String message = "1st App \"にゃ～ var 1.0.0\"\n\n";
			message += "This application is a present from M to Y. \n";
			message += "2012/04/28";

			new AlertDialog.Builder(this)
			.setMessage(message)
			.setPositiveButton("OK", null)
			.show();
			break;
		}
		return ret;
	}
	**/
}